/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wso.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import wso.dto.WsoOrderDetail;
import wso.global.BaseDao;

/**
 *
 * @author Violet_Ink
 */
public class OrderDetailDaoImpl extends BaseDao implements OrderDetailDao {

    public void saveOrUpdateOrderDetail(WsoOrderDetail orderdetail) {
        saveOrUpdate(orderdetail);
    }

    public void deleteOrderDetail(long orderdetailid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("update WsoOrderDetail od set od.isdeleted = true where od.orderdetailid = :orderdetailid");
        query = session.createQuery(str.toString());
        query.setLong("orderdetailid", orderdetailid);

        query.executeUpdate();
    }

    public WsoOrderDetail[] getAllOrderDetail() {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("from WsoOrderDetail od where od.isdeleted = false");
        query = session.createQuery(str.toString());
        List orderdetailList = query.list();
        WsoOrderDetail[] result = new WsoOrderDetail[orderdetailList.size()];
        orderdetailList.toArray(result);

        return result;
    }

    public WsoOrderDetail getOrderDetail(long orderdetailid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();

        str.append("from WsoOrderDetail od where od.orderdetailid = :orderdetailid and od.isdeleted = false");
        query = session.createQuery(str.toString());
        query.setLong("orderdetailid", orderdetailid);

        return (WsoOrderDetail) query.uniqueResult();
    }

}
